package com.xdkj.util;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.UploadObjectArgs;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.ServerException;
import io.minio.errors.XmlParserException;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2021/11/29 11:18
 */
public class FileUpLoad {
    public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient.Builder builder = MinioClient.builder();
        MinioClient minioClient = builder.endpoint("http://8.130.171.59:60000")
                .credentials("admin", "12345678")
                .build();
        boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("xdkj-cs").build());
        if (!found){
            minioClient.makeBucket(MakeBucketArgs.builder().bucket("xdkj-cs").build());
        }else {
            System.out.println("Bucket 'asiatrip' already exists.");
        }
        ObjectWriteResponse objectWriteResponse = minioClient.uploadObject(UploadObjectArgs.builder().bucket("xdkj-cs")
                .object("2.jpg")
                .filename("D:\\西点\\微信图片_20210902201640.jpg").build());
        System.out.println("successful!");
    }
}
